package ae.pcfc.cldos.online.web.factories;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import ae.pcfc.cldos.online.common.clddb.domain.Process;
import ae.pcfc.cldos.online.common.vo.AppMetaDataVO;
import ae.pcfc.cldos.online.web.ViewPath;

/**
 * 
 * @author akhader
 *
 */
public class AllAppDtlUrlFactory {



	private static List<AllAppDtlUrlFactory.ProcessAndUrl> ProcessAndUrlsCache = new ArrayList<AllAppDtlUrlFactory.ProcessAndUrl>();
	
	
	static{
		/**
		 * URL FOR 
		 */
		
		addNewUrl(new String[]{Process.PROCESS_EMPLOYMENT_VISA}, 
				ViewPath.__ADMIN_EMPLOYMENT_VISA_VIEW+"/form.htm");
		addNewUrl(new String[]{Process.PROCESS_VISIT_VISA}, 
				ViewPath.__COMPANY_VISIT_VISA_VIEW+"/form.htm");
		addNewUrl(new String[]{Process.PROCESS_EMPLOYMENT_VISA_RENEWAL}, 
				ViewPath.__ADMIN_EMPLOYMENT_VISA_RENEWAL_VIEW+"/form.htm");
		addNewUrl(new String[]{Process.PROCESS_EMPLOYMENT_VISA_CANCELATION}, 
				ViewPath.__ADMIN_EMPLOYMENT_VISA_TERMINATE_VIEW+"/form.htm");
		addNewUrl(new String[]{Process.PROCESS_CANCEL_VISIT_VISA}, 
				ViewPath.__ADMIN_EMPLOYMENT_VISA_CANCEL_VIEW+"/form.htm");
		addNewUrl(new String[]{Process.PROCESS_NOC_LETTERS}, 
				ViewPath.__NOC_LETTERS_VIEW+"/form.htm");
	
	}       
	
	
	private static void addNewUrl(String[] processCodes,String url){
		ProcessAndUrl ProcessAndUrl = new ProcessAndUrl();
		ProcessAndUrl.setProcessCodes(new HashSet<String>(Arrays.asList(processCodes)));
		ProcessAndUrl.setUrl(url);
		ProcessAndUrlsCache.add(ProcessAndUrl);
	}
	
	
	public static String getUrlByAppMetaDataVO(AppMetaDataVO appMetaDataVO){
		String result = null;
		String processCode = appMetaDataVO.getProcessCode();
		for(ProcessAndUrl ProcessAndUrl : ProcessAndUrlsCache){
			Set<String> processCodes = ProcessAndUrl.getProcessCodes();
			if(processCodes.contains(processCode)){
				result = ProcessAndUrl.getUrl();
				break;
			}
		}
		return result;
	}
	

	public static class ProcessAndUrl {
		private Set<String> processCodes;
		private String url;
		
		public Set<String> getProcessCodes() {
			return processCodes;
		}
		public void setProcessCodes(Set<String> processCodes) {
			this.processCodes = processCodes;
		}
		public String getUrl() {
			return url;
		}
		public void setUrl(String url) {
			this.url = url;
		}
	}
	
	
}
